/**
 * @param {number} target
 * @param {number[]} nums
 * @return {number}
 */
 var minSubArrayLen = function(target, nums) {
    let index =0
    let max = nums[index]
    for(let i=1;i<nums.length;i++){
        if(nums[i]>max){
            max=nums[i]
            console.log(nums[i])
            index = i
        }
    }
    console.log('max is '+max)
    console.log('index is '+index)
    console.log(nums.length)
    let sum = max
    let len = 1
    if(nums.length==1){
        if(sum>=target){
            return 1
        }else{
            return 0
        }
    }
    if(nums[index+1]>=nums[index-1]||index==0){
        for(len =1;sum<target;len++,index++){
            sum += nums[index+1]
            console.log('add '+nums[index+1])
            console.log('sum is '+sum)
        if(index+1==nums.length-1){
            if(sum >= target){
                return len+1
            }else{
                return 0
            }
        }
        }
    }else if(nums[index+1]<nums[index-1] ||index==nums.length-1){
        for(len =1;sum<target;len++,index--){
            sum+=nums[index-1]
        if(index-1==0){
            if(sum>=target){
                return len+1
            }else{
                return 0
            }
        }
        }
    }
    
    return len
};
// 16/19 好像改不对了 问题写在note里了